import argparse
from prefect import flow

from task import (
    connect_to_neo4j,
    get_config_from_toml,
    get_config_from_secret_block_as_json,
)


@flow(log_prints=True)
def neo4j_connect_bakflow(target: str, local: bool, file: str | None):
    """
    Given a neo4j aura instance, test connectivity.
    """
    print(f"target:{target}, local:{local}, file:{file}")
    config = {}
    if local:
        print("use local from toml")
        config = get_config_from_toml(target, file)
    else:
        print("use remote from secret block")
        config = (
            get_config_from_secret_block_as_json(target) if target is not None else {}
        )

    connect_to_neo4j(target=target, **config)


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("target")
    parser.add_argument("--local", action="store_true")
    parser.add_argument(
        "-f",
        "--file",
        default="neo4j.toml",
    )
    args = parser.parse_args()
    # print("args:", args)
    neo4j_connect_bakflow(**vars(args))
